package com.abp.controller;

import com.abp.entity.BookClusterPreference;
import com.abp.service.BookClusterPreferenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/book-cluster-preferences")
public class BookClusterPreferenceController {

    @Autowired
    private BookClusterPreferenceService bookClusterPreferenceService;

    // 获取所有图书聚类偏好
    @GetMapping
    public List<BookClusterPreference> getAllBookClusterPreferences() {
        return bookClusterPreferenceService.list();
    }

    // 根据聚类ID获取图书偏好信息
    @GetMapping("/{id}")
    public BookClusterPreference getBookClusterPreferenceById(@PathVariable int id) {
        return bookClusterPreferenceService.getById(id);
    }

    // 新增图书聚类偏好
    @PostMapping
    public boolean addBookClusterPreference(@RequestBody BookClusterPreference bookClusterPreference) {
        return bookClusterPreferenceService.save(bookClusterPreference);
    }

    // 更新图书聚类偏好
    @PutMapping("/{id}")
    public boolean updateBookClusterPreference(@PathVariable int id, @RequestBody BookClusterPreference bookClusterPreference) {
        bookClusterPreference.setClusterId(id);
        return bookClusterPreferenceService.updateById(bookClusterPreference);
    }

    // 删除图书聚类偏好
    @DeleteMapping("/{id}")
    public boolean deleteBookClusterPreference(@PathVariable int id) {
        return bookClusterPreferenceService.removeById(id);
    }
}
